<template>
	<view class="container">
		<view class="intro">
			<span class="iconfont icon-denglu"></span>
		</view>
		<view class="bottom">
<!-- 				<button type="primary" size="default" class="login-btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="getUserInfo">
					<image src="/static/images/mine/wechat.png"></image>
					微信一键登录
				</button> -->
				<button type="primary" size="default" class="login-btn"  lang="zh_CN" @click="getUserInfo">
					<image src="/static/images/mine/wechat.png"></image>
					<span v-if="loading==0" >登录</span>
					<span v-else >登录中...</span>
				</button>
			</view>
	</view>
</template>

<script>

	import {mapMutations} from 'vuex'
	const { wxLogin } = require("@/api/api/login.js")
	export default {
		data() {
			return {
				loading:0
			}
		},
		methods: {
		
			...mapMutations('user',['SET_TOKEN','SET_USER']),
			login(){
				wx.login({
				 
				}).then(res=>{
					if (res.code) {
					  //发起网络请求
					console.log(res)
					const param = {
						code:res.code
					}
					this.loading=1;
					wxLogin(param).then(res=>{
						console.log(res)
						// this.$store.commit("user/SET_TOKEN",res.token);
						this.loading=0;
						this.SET_TOKEN(res.data.token);
						this.SET_USER(res.data.user);
						uni.navigateBack()
						
					})			    
					} else {
				      this.loading=0;
					  console.log('登录失败！' + res.errMsg)
					}
				})
				
			},
			async getUserInfo() {
				this.login();

			},

		}
	}
</script>

<style lang="scss" scoped>
	.intro {
		width: 100%;
		height: 60vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-evenly;
		font-size: $font-size-base;
		color: $text-color-assist;
		
		image {
			width: 165rpx;
			height: 165rpx;
		}
		
		.tips {
			line-height: 72rpx;
			text-align: center;
		}
		.iconfont{
			font-size: 50px;
		}
	}
	
	.bottom {
		height: 40vh;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 0 40rpx;
		
		.login-btn {
			width: 100%;
			border-radius: 50rem !important;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 10rpx 0;
			
			image {
				width: 36rpx;
				height: 30rpx;
				margin-right: 10rpx;
			}
		}
		
		.row {
			.grid {
				width: 20%;
				image {
					width: 60rpx;
					height: 60rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>
